package net.huashitong.supervision.task.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.filter.Paging;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.supervision.task.entity.TaskCategory;
import net.huashitong.supervision.task.filter.TaskCategoryFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/8/6
 * Time: 20:26
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Repository
public class TaskCategoryDao  extends StringDao<TaskCategory> {
    public List<TaskCategory> queryFilter(TaskCategoryFilter filter) {
        GenericQuery obj = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getSearch())){
            obj.append(" and category like :category").setParam("category", StringUtils.getLikewords(filter.getSearch()));
        }
        if (ObjectUtils.isBlank(filter.getPaging())){
            Paging paging = new Paging(0);
            paging.setSortCol("indexNum");
            paging.setSortVal("asc");
            filter.setPaging(paging);
        }
        return obj.listResult(filter);
    }

    public int queryMaxIndex() {
        GenericQuery obj = createQuery("obj");
        obj.append(" and del is null");
        int size = obj.listResult().size();
        return size;
    }
}
